<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查看油卡</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
</head>
<body  >
<div class="layui-container">


    <form class="layui-form"  >
        <div class="layui-row">
            <div class="layui-col-md12">

                <fieldset class="layui-elem-field" style="margin-top: 20px;">
                    <legend>查看油卡</legend>



                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;"></span>油卡号</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input   type="text" name="ykh"  lay-verify="required" required   class="layui-input" id="ykh" >
                                <input   type="hidden" name="ykid"    id="ykid" >
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;"></span>加油站</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input   type="text" name="jyz"  lay-verify="required" required   class="layui-input" id="jyz" >
                            </div>
                        </div>


                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;"><span style="color: red;"></span>购卡日期</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input   type="text" name="gkrq"  lay-verify="required" required   class="layui-input" id="gkrq" lay-filter = "gkrq">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;"><span style="color: red;"></span>油卡类别</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <div class="layui-input-inline layui-form" style="width: 140px;">
                                    <input   type="text" name="yklb"  lay-verify="required" required   class="layui-input" id="yklb" lay-filter = "yklb">

                                </div>
                            </div>
                        </div>



                    </div>



                </fieldset>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-md12">
                <fieldset class="layui-elem-field" style="margin-top: 20px;">
                    <legend>充值明细</legend>


                    <div class="layui-form-item">
                        <label class="layui-form-label"> 充值日期 </label>
                        <div class="layui-input-inline" style="width: 150px;">
                            <input   type="text"      class="layui-input" id="czrq" lay-filter = "czrq">
                            <input   type="hidden" name="czmxm"   id="czmxData"    >
                        </div>





                        <label class="layui-form-label" style="width: 92px"> 充值金额</label>

                        <div class="layui-input-inline" style="width: 150px;">
                            <input   type="text" name=""   id="czje" placeholder="请输入"  class="layui-input"  >
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 82px">支付方式</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input   type="text" name="zffs" id="zffs"   placeholder="请输入"  class="layui-input"  >
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 75px">经办人</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name=""  placeholder="请输入"  id="jbr"  class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" style="position: relative;left: 87%">
                            <button type="button" class="layui-btn layui-btn-normal" id="addRecharge">添加到下方</button>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-form-item">
                            <script type="text/html" id="opera">
                                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                            </script>

                            <table id="czmx" lay-filter="czmx"></table>

                        </div>

                    </div>



                </fieldset>
            </div>
        </div>

        <button id="modiSub" lay-submit  class="layui-btn layui-btn-normal " lay-filter="update" style="width: 10%; position: absolute;left: 45%"  >立即提交</button>
    </form>
</div>
<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/tools.js"></script>
<script src="../js/jquery.js"></script>
<script src="../js/jquery.md5.js"></script>

<script>
    layui.use(['table','form','layer','laydate','upload'],function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var upload = layui.upload;

//        $("#addRecharge").attr("disabled",true);
//        $("#addRecharge").addClass("layui-btn-disabled");
        $("#ykh").addClass("layui-disabled");
        $("#ykh").attr("disabled",true);
        $("#jyz").addClass("layui-disabled");
        $("#jyz").attr("disabled",true);
        $("#gkrq").addClass("layui-disabled");
        $("#gkrq").attr("disabled",true);
        $("#yklb").addClass("layui-disabled");
        $("#yklb").attr("disabled",true);
        $("select").attr("disabled","disabled");
        $("#modiSub").removeClass("layui-btn-disabled");
        $("#modiSub").removeAttr("disabled");
        $("#czrq").removeClass("layui-btn-disabled");
        $("#czrq").attr("disabled",false);
        $("#czje").removeClass("layui-btn-disabled");
        $("#czje").attr("disabled",false);
        $("#zffs").removeClass("layui-btn-disabled");
        $("#zffs").attr("disabled",false);
        $("#jbr").removeClass("layui-btn-disabled");
        $("#jbr").attr("disabled",false);

        //日期控件渲染


        laydate.render({
            elem: '#czrq' //指定元素
            ,theme:'#0099FF'
            ,value: getFormatDate()
            ,type: 'date'
            ,format:'yyyy-MM-dd'
        });
        //渲染表格
        var czmxArr = JSON.parse( $("#czmxData").val());
        console.log(czmxArr);
        table.render({
            elem:'#czmx'
            ,page:true
            ,cellMinWidth: 80
            ,data:czmxArr
            ,limit:5
            ,cols: [[
                {type:'numbers', title: '序号',  align:'center'}
                ,{field:'czrq', title: '充值日期' ,align: 'center' }
                ,{field:'czje', title: '充值金额' ,align: 'center' }
                ,{field:'zffs', title: '支付方式' ,align: 'center' }
                ,{field:'jbr', title: '经办人' ,align: 'center' }
                ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera' ,width:150}

            ]]
        });

        $("#addRecharge").on('click',function () {
            console.log(czmxArr);
            var elem = {};
            var czrq = $("#czrq").val();
            var czje = $("#czje").val();
            var zffs = $("#zffs").val();
            var jbr = $("#jbr").val();
            $("#jbr").val("");
            $("#czrq").val("");
            $("#czje").val("");
            $("#zffs").val("");

            if(czrq&&czje&&zffs&&jbr){
                elem.czrq = czrq;
                elem.czje = czje;
                elem.zffs = zffs;
                elem.jbr = jbr;

                czmxArr.push(elem);

                table.render({
                    elem:'#czmx'
                    ,page:true
                    ,cellMinWidth: 80
                    ,data:czmxArr
                    ,limit:5
                    ,cols: [[
                        {type:'numbers', title: '序号',  align:'center'}
                        ,{field:'czrq', title: '充值日期' ,align: 'center' }
                        ,{field:'czje', title: '充值金额' ,align: 'center' }
                        ,{field:'zffs', title: '支付方式' ,align: 'center' }
                        ,{field:'jbr', title: '经办人' ,align: 'center' }
                        ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera' ,width:150}

                    ]]
                });
            }else {
                layer.msg("充值信息不能为空");
            }
        });

        //渲染部门
        $.ajax({
            url: contextPath+"/dept/" ,
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                console.log(res);
                for(var i in res.list){
                    if($("#ssbmHid").val() ==  res.list[i].bumenid){
                        var option = "<option selected value='"+ res.list[i].bumenid+ "'>"+res.list[i].name+"</option>";
                    }else {
                        var option = "<option value='"+ res.list[i].bumenid+ "'>"+res.list[i].name+"</option>";
                    }


                    $("#ssbm").append(option);
                };
                form.render('select');
            }
        });
        //table tool
        table.on('tool(czmx)', function(obj){
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'del'){

                $.each(czmxArr,function (i,e) {
                    if(e.czrq == data.czrq && e.czje == data.czje&& e.zffs == data.zffs&& e.jbr == data.jbr){
                        czmxArr.splice(i,1);
                    }
                })
                table.render({
                    elem:'#czmx'
                    ,page:true
                    ,cellMinWidth: 80
                    ,data:czmxArr
                    ,limit:5
                    ,cols: [[
                        {type:'numbers', title: '序号',  align:'center'}
                        ,{field:'czrq', title: '充值日期' ,align: 'center' }
                        ,{field:'czje', title: '充值金额' ,align: 'center' }
                        ,{field:'zffs', title: '支付方式' ,align: 'center' }
                        ,{field:'jbr', title: '经办人' ,align: 'center' }
                        ,{fixed: 'right',title:'操作', align:'center', toolbar: '#opera' ,width:150}

                    ]]
                });


            }
        });
     form.on('submit(update)', function(data){
            data.field.czmxm = JSON.stringify(czmxArr) ;
            console.log(data.field);
            $("input").css("border","");
            $.ajax({
                url: contextPath+"/oilcard",
                type: "PUT",
                contentType:"application/json;charset=utf-8",
                data: JSON.stringify(data.field) ,
                dataType:"json",
                success: function(res) {
                    updateSuccess($,layer,res);
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });

</script>
</body>
</html>